package cn.woniu.ecommerceplatform.service.impl;

import cn.woniu.ecommerceplatform.entity.Menu1;
import cn.woniu.ecommerceplatform.entity.Menu3;
import cn.woniu.ecommerceplatform.mapper.MenuMapper;
import cn.woniu.ecommerceplatform.redis.RedisMenusRepositiry;
import cn.woniu.ecommerceplatform.service.MenuService;
import cn.woniu.ecommerceplatform.util.ResponseResult;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author QIQI
* @description 针对表【menu1】的数据库操作Service实现
* @createDate 2022-12-15 09:09:00
*/
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu1>
    implements MenuService {
    @Autowired(required = false)
    private MenuMapper mapper;
    @Autowired(required = false)
    private RedisMenusRepositiry redisMenusRepositiry;
    @Override
    public ResponseResult<List<Menu1>> menuList() {
//        List<> all = (List<>) redisMenusRepositiry.findAll();
        List<Menu1> menu1s=null;
        menu1s = (List<Menu1>) redisMenusRepositiry.findAll();
        if(menu1s.isEmpty()){
            menu1s = mapper.menuList();
            redisMenusRepositiry.saveAll(menu1s);
        }
        return new ResponseResult<List<Menu1>>().ok(menu1s);
    }

    @Override
    public ResponseResult<List<Menu3>> menuListCustomer() {
        List<Menu3> menu3s = mapper.menuListCustomer();
        return new ResponseResult<List<Menu3>>().ok(menu3s);
    }
}




